<?php
error_reporting(0);
require_once 'model/api/Taoapi.php';
require_once 'config.php';

$page = !($_GET['page'])?'0':intval($_GET['page']);
$sort=$_GET['sort'];
if($sort=='')
  {$sort='commissionNum_desc';}
$sp = !($_GET['sp'])?1:intval($_GET['sp']);
$ep = !($_GET['ep'])?999999:intval($_GET['ep']);
$area=!$_GET['area']?"":$_GET['area'];
$liebiao_search = isset($_GET['liebiao'])?intval($_GET['liebiao']):$liebiao_search;
$cid = !($_GET['cid'])?0:intval($_GET['cid']);
$q=empty($_GET['q'])? '女装':htmlspecialchars($_GET['q']);

$tplFile="slist.html";
$tplCache=$cid.$page.$sort.$sp.$ep.$area.$liebiao_search.$q;
$smar=new MySmarty($cache,$cachetime,$moban);
$smarty=$smar->get_smarty();
if(!$smarty->is_cached($tplFile,$tplCache)){
	$Taoapi_Config = Taoapi_Config::Init();
	$Taoapi_Config->setCharset('UTF-8');
	$Taoapi_Config->setAppKey($app);

	$Taoapi = new Taoapi;
	$Taoapi->method = 'taobao.taobaoke.items.get';
	$Taoapi->fields = 'num_iid,title,nick,pic_url,price,click_url,volume,seller_credit_score,shop_click_url';
	$Taoapi->keyword = $q;
	$Taoapi->cid = $cid;
	if($sp!=1||$ep!=999999){
		$Taoapi->start_price = $sp;
		$Taoapi->end_price = $ep;
	}
	$Taoapi->start_commissionRate = $start_commissionRate;
	$Taoapi->end_commissionRate = $end_commissionRate;
	$Taoapi->page_no = $page;
	$Taoapi->page_size = '16';
	$Taoapi->area = $area;
	$Taoapi->sort = $sort;
	$Taoapi->nick = $usernick;
	//需要更多的字段可以登陆 taoapi.com 进行配置生成
	$result = $Taoapi->Send('get','xml')->getArrayData();
	$taobaokeItem = $result['taobaoke_items']['taobaoke_item'];
	$totalResults = $result['total_results'];
	
	$prefixurl="huangguandianpu";
	$nav="<a href='".$website."/search-".urlencode($q).$ljoin.$lcat.$cid.$ljoin.$lpage."0".$rewrite_postfix."'>".$q."</a>";
	include("head.php");
	if($taobaokeItem[1]){
		foreach($taobaokeItem as $row) {
			$row["pic_url"]=base64_encode($row["pic_url"]);
			$row["title"]=strip_tags($row["title"]);
			$row["click_url"]=base64_encode($row["click_url"]);
			$proItems[]=$row;
		}
	}elseif($taobaokeItem[0]){
		$taobaokeItem["pic_url"]=base64_encode($taobaokeItem["pic_url"]);
		$taobaokeItem["title"]=strip_tags($taobaokeItem["title"]);
		$taobaokeItem["click_url"]=base64_encode($taobaokeItem["click_url"]);
		$proItems[]=$taobaokeItem;
	}
	
	$surl=getsearchurl($cid);
	require_once("pages.php");    
	  $page_size=20;    
	  $nums=$totalResults;     
	  $sub_pages=10;   
	  $pageCurrent=$_GET["page"];      
	  $subPages=new SubPages($page_size,$nums,$pageCurrent,$sub_pages,$website."/search".$surl.$lpage,2,$rewrite_postfix);
	  $pagestr=$subPages->getstr();
	include("foot.php");
	
	//head
	$smarty->assign("thistitle",$thistitle);
	$smarty->assign("q",$q);
	$smarty->assign("result2",$result2);
	$smarty->assign("webname",$webname);
	$smarty->assign("postfix",$postfix);
	$smarty->assign("description",$description);
	$smarty->assign("keywords",$keywords);
	$smarty->assign("website",$website);
	$smarty->assign("searchkeys",$searchkeys);
	$smarty->assign("newshops",$newshops);
	$smarty->assign("toubiao",$show_topnav);
$smarty->assign("moban",$moban);
$smarty->assign("thispid",$thispid);

	
	//category
	$smarty->assign("prefixurl",$prefixurl);
	$smarty->assign("lcat",$lcat);
	$smarty->assign("lpro",$lpro);
	$smarty->assign("lpage",$lpage);
	$smarty->assign("rewrite_postfix",$rewrite_postfix);
	$smarty->assign("ljoin",$ljoin);
	//foot
	$smarty->assign("links",$links);
	$smarty->assign("QQ",$QQ);
	$smarty->assign("ICP",$ICP);
	$smarty->assign("tongji",$tongji);
$smarty->assign("jiathis",$jiathis);
	//slist
	$smarty->assign("proItems",$proItems);
	$smarty->assign("subPages",$pagestr);
	$smarty->assign("nav",$nav);
	$smarty->assign("spre",'search');
	$smarty->assign("sp",$sp);
	$smarty->assign("ep",$ep);
	$smarty->assign("page",$page);
	$smarty->assign("liebiao",$liebiao_search);
	$smarty->assign("showcid",1);
	$smarty->assign("cid",$cid);
	$smarty->assign("sort",$sort);
	$smarty->assign("area",$area);
}
$smarty->display($tplFile,$tplCache);
?>
